package com.hrhx.duhongming.adapter;

import java.util.Map;

import com.github.abel533.echarts.code.SeriesType;
import com.github.abel533.echarts.data.Data;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Line;
import com.hrhx.duhongming.bean.EchartsConfig;

public class EchartsPieAdapter {
	
	//pie的适配器入口
	public static GsonOption adapter(
			EchartsConfig echartsConfig,
			GsonOption gsonOption,
			Map<String,Object> data){
		EchartsPieAdapter pieAdapter = new EchartsPieAdapter();
		gsonOption = pieAdapter.legendAdapter(gsonOption, data);
		gsonOption = pieAdapter.seriesAdapter(echartsConfig,gsonOption, data);
		return gsonOption;
	}
		
	//legend
	public GsonOption legendAdapter(
			GsonOption gsonOption,
			Map<String,Object> data){
		if(data != null){
			for (String key : data.keySet()) {
				gsonOption.legend().data(key);
			}
		}
		return gsonOption;
	}
	//radius轴数据处理
	public GsonOption seriesAdapter(
			EchartsConfig echartsConfig,
			GsonOption gsonOption,
			Map<String,Object> orientData){
		if (orientData != null) {
			Line line = new Line();
			//饼图数值显示
			//if(itemStyleShow){
				line.itemStyle().normal().label()
											//.show(itemStyleShow)
											.formatter("{b} : {c}");
			//}
			if("pie".equalsIgnoreCase(echartsConfig.getType())){				
				line.name(echartsConfig.getTitle()).type(SeriesType.pie);
			}else if("funnel".equalsIgnoreCase(echartsConfig.getType())){
				line.name(echartsConfig.getTitle()).type(SeriesType.funnel);
			}else if("rose".equalsIgnoreCase(echartsConfig.getType())){
				line.name(echartsConfig.getTitle()).type(SeriesType.pie).roseType("radius");
			}
			for (String title : orientData.keySet()) {
				Object value = orientData.get(title);		
				line.data(new Data().name(title).value(value));				
			}
			gsonOption.series(line);
		}
		return gsonOption;
	}
}
